package com.dahong.cloud.authorize.config;

import cn.hutool.core.bean.BeanUtil;
import com.dahong.cloud.authorize.domain.SimpleUser;
import com.dahong.cloud.authorize.mapper.SimpleUserMapper;
import com.lambda.cloud.core.principal.LoginUser;
import com.lambda.security.SimpleLoginUser;
import com.lambda.security.service.UserDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@SuppressWarnings("all")
@Service
public class UserDetailServiceImpl implements UserDetailService {

    SimpleUserMapper userMapper;

    @Autowired
    public void setUserMapper(SimpleUserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public LoginUser loginByUsername(String username, String loginType) {
        SimpleLoginUser currentUser = new SimpleLoginUser();
        SimpleUser simpleUser = userMapper.selectById(username);
        BeanUtil.copyProperties(simpleUser, currentUser);
        currentUser.setUsername(simpleUser.getUsername());
        currentUser.setPassword(simpleUser.getPassword());
        return currentUser;
    }

    @Override
    public LoginUser loginByMobile(String mobile, String loginType) {
        SimpleLoginUser currentUser = new SimpleLoginUser();
        currentUser.setUsername(mobile);
        currentUser.setPassword("123456");
        currentUser.setAccountExpired(false);
        currentUser.setAccountLocked(false);
        return currentUser;
    }
}
